JAVA_HOME=/usr/lib/jdk/jdk1.8.0_161
JNI_INCLUDE=-I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux 

D_LIBMSLOG_LIBS :=`pkg-config --libs libmslog`
D_LIBMSLOG_INCLUDES :=`pkg-config --cflags libmslog`
D_LIBMSCOMMON_LIBS :=`pkg-config --libs libmscommon`
D_LIBMSCOMMON_INCLUDES :=`pkg-config --cflags libmscommon`
D_LIBMSPROTOCOL_LIBS :=`pkg-config --libs libmsprotocol`
D_LIBMSPROTOCOL_INCLUDES :=`pkg-config --cflags libmsprotocol`
D_LIBDRM_LIBS :=`pkg-config --libs libmsdrm`
D_LIBDRM_INCLUDES :=`pkg-config --cflags libmsdrm`

C_INCLUDE=${D_BASEAPI_FLAGS} -Isrc ${D_LIBMSLOG_INCLUDES} ${D_LIBMSCOMMON_INCLUDES} ${D_LIBMSPROTOCOL_INCLUDES}
C_LIBS=${D_LIBMSLOG_LIBS} ${D_LIBMSCOMMON_LIBS} ${D_LIBMSPROTOCOL_LIBS}


libmsdrm_CC=${CC}
libmsdrm_SRC=${C_SRC}
libmsdrm_CFLAGS=${C_INCLUDE} ${C_LIBS} ${CFLAGS_SHARE} 

libmsdrmjni_CC=${CC}
libmsdrmjni_SRC=src/jni/msdrmjni.c
libmsdrmjni_CFLAGS=${C_INCLUDE} ${C_LIBS} ${CFLAGS_SHARE} ${JNI_INCLUDE} ${D_LIBDRM_LIBS} ${D_LIBDRM_INCLUDES}

msdrm_sample_CC=${CC}
msdrm_sample_SRC=msdrm_sample.c
msdrm_sample_CFLAGS=${C_INCLUDE} ${D_LIBDRM_INCLUDES} ${C_LIBS} -lmsdrm

x8664: libmsdrm install msdrm_sample
	
libmsdrm: 
	mkdir -p $(OUT_LIB)
	mkdir -p $(OUT_INCLUDE)
	cp -fr src/*.h $(OUT_INCLUDE)
	$($@_CC)  $($@_SRC)  $($@_CFLAGS)  -o $(OUT_LIB)/$(PROGRAM_NAME).so 
gdbs: 
	mkdir -p $(OUT_LIB)
	mkdir -p $(OUT_INCLUDE)
	cp -fr src/*.h $(OUT_INCLUDE)
	$(libmsdrm_CC)  $(libmsdrm_SRC)  $(libmsdrm_CFLAGS) -g -o $(OUT_LIB)/$(PROGRAM_NAME).so  	
	
libmsdrmjni: libmsdrm install
	mkdir -p $OUT_JNISRC
	mkdir -p $OUT_JNILIB
	mkdir -p $OUT_JNIINCLUDE
	cp -fr src/jni/*				$OUT_JNISRC
	cp -fr ${prefix_x8664}/lib/libmslog.so		$OUT_JNILIB	
	cp -fr ${prefix_x8664}/lib/libmscommon.so	$OUT_JNILIB
	cp -fr ${prefix_x8664}/lib/libmsprotocol.so	$OUT_JNILIB
	cp -fr ${prefix_x8664}/libmsauthent.so		$OUT_JNILIB
	cp -fr ${prefix_x8664}/libmsdrm.so		$OUT_JNILIB
	cp -fr ${prefix_x8664}/include/libmslog	$OUT_JNIINCLUDE		
	cp -fr ${prefix_x8664}/include/libmscommon	$OUT_JNIINCLUDE	
	cp -fr ${prefix_x8664}/include/libmstool	$OUT_JNIINCLUDE	
	cp -fr ${prefix_x8664}/include/libmsdrm	$OUT_JNIINCLUDE


msdrm_sample: 
	mkdir -p $(OUT_BIN)
	$($@_CC)  $($@_SRC)  $($@_CFLAGS)  -o $(OUT_BIN)/$@ 
	
install:
	mkdir -p  ${prefix_x8664}/lib/ 
	mkdir -p  ${prefix_x8664}/include/   
	mkdir -p  ${prefix_x8664}/lib/pkgconfig/ 
	cp -fr $(OUT_LIB)/$(PROGRAM_NAME).so	${prefix_x8664}/lib/     
	cp -fr $(OUT_INCLUDE)			${prefix_x8664}/include/	     
	cp -fr platform/$(PROGRAM_NAME).pc	${prefix_x8664}/lib/pkgconfig/
install_gdb:
	mkdir -p  ${prefix_x8664}/lib_gdb/ 
	mkdir -p  ${prefix_x8664}/include/   
	mkdir -p  ${prefix_x8664}/lib/pkgconfig/ 
	cp -fr $(OUT_LIB)/$(PROGRAM_NAME).so	${prefix_x8664}/lib_gdb/     
	cp -fr $(OUT_INCLUDE)			${prefix_x8664}/include/	     
	cp -fr platform/$(PROGRAM_NAME).pc	${prefix_x8664}/lib/pkgconfig/
uninstall:
	rm -fr ${prefix_x8664}/lib/$(PROGRAM_NAME).so 
	rm -fr ${prefix_x8664}/include/$(PROGRAM_NAME)
	rm -fr ${prefix_x8664}/lib/pkgconfig/$(PROGRAM_NAME).pc
